#include <bits/stdc++.h>
#include <string>
using namespace std;

int main()
{
	int n, m, l, k, x, y;
	l = k = 0;
	// 当前病毒的人房间坐标
	int virus[10005][2];
	// 方向  上 下 左 右
	int ways[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	cin >> n;
	// 房间
	char room[n][n];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> room[i][j];
			if (room[i][j] == '@')
			{
				virus[k][0] = i;
				virus[k][1] = j;
				k++;
			}
		}
	}
	cin >> m;
	while (--m)
	{
		int start = l,end = k;
		l = k;
		for (int i = start; i < end; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				x = virus[i][0]+ways[j][0];
				y = virus[i][1]+ways[j][1];
				if(x>=0&&x<n&&y>=0&&y<n&&room[x][y]=='.'){
                   virus[k][0] = x;
				   virus[k][1] = y;
				   k++;
				   room[x][y] = '@';
				}
			}
		}
	}
	cout << k;
	return 0;
}